/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifdef __cplusplus
extern "C" {
#endif
#include "Std_Types.h"
#include "Det.h"
#include "Dem.h"
#include "cdefs.h"
#if defined(DEBUG_ENABLE)
#include "debug.h"
#endif
/* Version and Check Begin */
/* Version Info Begin */
#define DET_C_VENDOR_ID    0x8C
#define DET_C_AR_RELEASE_MAJOR_VERSION    4
#define DET_C_AR_RELEASE_MINOR_VERSION    3
#define DET_C_AR_RELEASE_REVISION_VERSION 1
#define DET_C_SW_MAJOR_VERSION    1
#define DET_C_SW_MINOR_VERSION    0
#define DET_C_SW_PATCH_VERSION    0
/* Version Info End */

/* Version Check Begin */
#if !defined(DISABLE_MCAL_ASR_VER_CHECK)
#if ((DET_C_AR_RELEASE_MAJOR_VERSION != STD_TYPES_H_AR_RELEASE_MAJOR_VERSION)\
    || (DET_C_AR_RELEASE_MINOR_VERSION != STD_TYPES_H_AR_RELEASE_MINOR_VERSION)\
    || (DET_C_AR_RELEASE_REVISION_VERSION != STD_TYPES_H_AR_RELEASE_REVISION_VERSION))
#error "Opps, Det.c and Std_Types.h AutoSAR version not match!"
#endif
#endif  /* !DISABLE_MCAL_ASR_VER_CHECK */
#if !defined(DISABLE_MCAL_SW_VER_CHECK)
#if ((DET_C_SW_MAJOR_VERSION != STD_TYPES_H_SW_MAJOR_VERSION)\
    || (DET_C_SW_MINOR_VERSION != STD_TYPES_H_SW_MINOR_VERSION)\
    || (DET_C_SW_PATCH_VERSION != STD_TYPES_H_SW_PATCH_VERSION))
#error "Opps, Det.c and Std_Types.h Software version not match!"
#endif
#endif  /* !DISABLE_MCAL_SW_VER_CHECK */
#if !defined(DISABLE_MCAL_ASR_VER_CHECK)
#if ((DET_C_AR_RELEASE_MAJOR_VERSION != DET_H_AR_RELEASE_MAJOR_VERSION)\
    || (DET_C_AR_RELEASE_MINOR_VERSION != DET_H_AR_RELEASE_MINOR_VERSION)\
    || (DET_C_AR_RELEASE_REVISION_VERSION != DET_H_AR_RELEASE_REVISION_VERSION))
#error "Opps, Det.c and Det.h AutoSAR version not match!"
#endif
#endif  /* !DISABLE_MCAL_ASR_VER_CHECK */
#if !defined(DISABLE_MCAL_SW_VER_CHECK)
#if ((DET_C_SW_MAJOR_VERSION != DET_H_SW_MAJOR_VERSION)\
    || (DET_C_SW_MINOR_VERSION != DET_H_SW_MINOR_VERSION)\
    || (DET_C_SW_PATCH_VERSION != DET_H_SW_PATCH_VERSION))
#error "Opps, Det.c and Det.h Software version not match!"
#endif
#endif  /* !DISABLE_MCAL_SW_VER_CHECK */
/* Version Check End */
/* Version and Check End */
#include "debug.h"
/*PRQA S 0605  EOF*/
/* Variables to record the last error */
VAR(uint16, DET_VAR) Det_ModuleId _SECTION(.dma_buffer);;
VAR(uint8, DET_VAR) Det_InstanceId _SECTION(.dma_buffer);;
VAR(uint8, DET_VAR) Det_ApiId _SECTION(.dma_buffer);;
VAR(uint8, DET_VAR) Det_ErrorId _SECTION(.dma_buffer);;


/* volatile VAR(uint8, DET_VAR) Det_DummyFlag; */

FUNC(void, DET_CODE) Det_Init(const Det_ConfigType *ConfigPtr)
{

}

FUNC(Std_ReturnType, DET_CODE) Det_ReportError(
    VAR(uint16, AUTOMATIC) ModuleId,
    VAR(uint8, AUTOMATIC) InstanceId,
    VAR(uint8, AUTOMATIC) ApiId,
    VAR(uint8, AUTOMATIC) ErrorId
)
{
#if defined(CFG_NOT_USED_AUTOSAR_OS)
    Det_ModuleId = ModuleId;
    Det_InstanceId = InstanceId;
    Det_ApiId = ApiId;
    Det_ErrorId = ErrorId;
    /* Just for temp used */
    /*PRQA S 3200 2*/
    PRINT("Det:ReportError: Module %d, Instance %d, Api %d, Error %d\n",
        ModuleId, InstanceId, ApiId, ErrorId);
#else
    while(1);
#endif
    /* Never return, but has a return type for compatibility */
    /*while (Det_DummyFlag == 0u);*/

    return E_OK;
}

FUNC(Std_ReturnType, DET_CODE) Det_ReportRuntimeError(
    VAR(uint16, AUTOMATIC) ModuleId,
    VAR(uint8, AUTOMATIC) InstanceId,
    VAR(uint8, AUTOMATIC) ApiId,
    VAR(uint8, AUTOMATIC) ErrorId
)
{
#if defined(CFG_NOT_USED_AUTOSAR_OS)
    Det_ModuleId = ModuleId;
    Det_InstanceId = InstanceId;
    Det_ApiId = ApiId;
    Det_ErrorId = ErrorId;
    /* Just for temp used */
    /*PRQA S 3200 2*/
    PRINT("Det:ReportRuntimeError: Module %d, Instance %d, Api %d, Error %d\n",
        ModuleId, InstanceId, ApiId, ErrorId);
#else
    while(1);
#endif
    return E_OK;
}

FUNC(Std_ReturnType, DET_CODE) Det_ReportTransientFault(
    VAR(uint16, AUTOMATIC) ModuleId,
    VAR(uint8, AUTOMATIC) InstanceId,
    VAR(uint8, AUTOMATIC) ApiId,
    VAR(uint8, AUTOMATIC) ErrorId
)
{
#if defined(CFG_NOT_USED_AUTOSAR_OS)
    Det_ModuleId = ModuleId;
    Det_InstanceId = InstanceId;
    Det_ApiId = ApiId;
    Det_ErrorId = ErrorId;
    /* Just for temp used */
    /*PRQA S 3200 2*/
    PRINT("Det:ReportTransientFault: Module %d, Instance %d, Api %d, Error %d\n",
        ModuleId, InstanceId, ApiId, ErrorId);
#else
    while(1);
#endif
    return E_OK;
}

FUNC(void, DET_CODE) Det_GetVersionInfo(
    P2VAR(Std_VersionInfoType, AUTOMATIC, DET_APPL_DATA) versioninfo
)
{
    if (NULL_PTR != versioninfo) {
        versioninfo->vendorID = DET_H_VENDOR_ID;
        versioninfo->moduleID = DET_MODULE_ID;
        versioninfo->sw_major_version = DET_H_SW_MAJOR_VERSION;
        versioninfo->sw_minor_version = DET_H_SW_MINOR_VERSION;
        versioninfo->sw_patch_version = DET_H_SW_PATCH_VERSION;
    }
}

FUNC(void, DET_CODE) Det_Start(void)
{

}
FUNC(sint32, DET_CODE) Det_Validate(
    VAR(uint16, AUTOMATIC) ModuleId,
    VAR(uint8, AUTOMATIC) InstanceId,
    VAR(uint8, AUTOMATIC) ApiId,
    VAR(uint8, AUTOMATIC) ErrorId
)
{
    if(Det_ModuleId != ModuleId){
        return -1;
    }
    if(Det_InstanceId != InstanceId){
        return -1;
    }
    if(Det_ApiId != ApiId){
        return -1;
    }
    if(Det_ErrorId !=  ErrorId){
        return -1;
    }
    return 0;
}
FUNC(void, DET_CODE) Det_Clean(void)
{
    Det_ModuleId = 0;
    Det_InstanceId = 0;
    Det_ApiId = 0;
    Det_ErrorId = 0;

}

FUNC(void, DEM_CODE) Dem_SetEventStatus(Dem_EventIdType EventId,Dem_EventStatusType EventStatus)
{
#if defined(CFG_NOT_USED_AUTOSAR_OS)
    /*PRQA S 3200 2*/
    PRINT("Dem:Report:Event %dEventStatus %d\n",EventId, EventStatus);
#else
    while(1);
#endif
}

#ifdef __cplusplus
}
#endif
